﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using MxWeiXinPF.BLL;


namespace MxWeiXinPF.Web.admin.jiaoshuifei
{
    public partial class baseinfo : Web.UI.ManagePage
    {
        MxWeiXinPF.BLL.shuifei_baseinfo bll = new MxWeiXinPF.BLL.shuifei_baseinfo();
        wx_requestRule rBll = new wx_requestRule();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowInfo();
            }
        }

        #region 赋值操作=================================
        private void ShowInfo()
        {
            ChkAdminLevel("jiaoshuifei_setting", MXEnums.ActionEnum.View.ToString()); //检查权限

            Model.wx_userweixin weixin = GetWeiXinCode();
            //网址
            lblIndexUrl.Text = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/index.aspx?wid=" + weixin.id;
            lblBind.Text = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/bindone.aspx?wid=" + weixin.id;
            lblBindList.Text = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/bindlist.aspx?wid=" + weixin.id;
            lblJaoFei.Text = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/payment.aspx?wid=" + weixin.id;
            lblZhangDan.Text = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/billByNo.aspx?wid=" + weixin.id;
            lblJiLu.Text = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/waterbyno.aspx?wid=" + weixin.id;
            lblBaoXiu.Text = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/repairlist.aspx?wid=" + weixin.id;

            IList<MxWeiXinPF.Model.shuifei_baseinfo> modellist = bll.GetModelList("wid=" + weixin.id);
            if (modellist == null || modellist.Count <= 0)
            {
                return;
            }
            MxWeiXinPF.Model.shuifei_baseinfo model = modellist[0];
            this.lblbaseId.Text = model.id.ToString();
            txtcontact_person.Text = model.contact_person.ToString();
            txttel.Text = model.tel.ToString();
            txttips.Text = model.tips.ToString();
            txtapi_url.Text = model.api_url.ToString();
            txtapi_UserName.Text = model.api_UserName.ToString();
            txtapi_Key.Text = model.api_Key.ToString();
            if (model.index_bg_pic != null && model.index_bg_pic.ToString().Trim() != "")
            {
                imgUrl.ImageUrl= model.index_bg_pic.ToString();
                txtImgUrl.Text = model.index_bg_pic.ToString();
            }

        }
        #endregion



        /// <summary>
        /// 保存配置信息
        /// </summary>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
         

            try
            {
                ChkAdminLevel("jiaoshuifei_setting", MXEnums.ActionEnum.Edit.ToString()); //检查权限

                MxWeiXinPF.Model.shuifei_baseinfo model = new MxWeiXinPF.Model.shuifei_baseinfo();
                Model.wx_userweixin weixin = GetWeiXinCode();
              
                int id = MyCommFun.Str2Int(lblbaseId.Text.Trim(),0);
                if (id != 0)
                {
                    model = bll.GetModel(id);
                }

                model.contact_person = txtcontact_person.Text.ToString().Trim();
                model.tel = txttel.Text.ToString().Trim();
                model.tips = txttips.Text.ToString().Trim();
                model.api_url = txtapi_url.Text.ToString().Trim();
                model.api_UserName = txtapi_UserName.Text.ToString().Trim();
                model.api_Key = txtapi_Key.Text.ToString().Trim();
                model.index_bg_pic = txtImgUrl.Text.ToString().Trim();
                bool ret = false;
                if (id != 0)
                {
                    model.update_time = DateTime.Now;
                    ret= bll.Update(model);
                    if (ret)
                    {
                        AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改缴水费参数设置成功"); //记录日志
                        JscriptMsg("设置缴水费参数设置成功！", "baseinfo.aspx");
                    }
                    else
                    {
                        AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改缴水费参数设置失败"); //记录日志
                        JscriptMsg("设置缴水费参数设置失败！", "baseinfo.aspx");
                    }
                }
                else
                {
                    model.create_time = DateTime.Now;
                    model.wid = weixin.id;
                    model.create_person = GetAdminInfo().user_name;

                    id = bll.Add(model);
                    if (id > 0)
                    {
                        ret = true;
                    }
                    if (ret)
                    {
                        AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "新增缴水费参数设置成功"); //记录日志
                        JscriptMsg("设置缴水费参数设置成功！", "baseinfo.aspx");
                    }
                    else
                    {
                        AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "新增缴水费参数设置失败"); //记录日志
                        JscriptMsg("设置缴水费参数设置失败！", "baseinfo.aspx");
                    }
                  
                }

              
            }
            catch
            {
                JscriptMsg("修改缴水费参数设置失败！", "");
            }
        }

         

         

    }
}